<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>调度任务日志</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <script src="/style/public/publicStyle.js"></script>
    <script>
        /*layui.use(['form'], function() {
            var form = layui.form,
                $ = layui.jquery;
            $(function() {
                if(pageloadauthority("/views/jobgroup.html")==true){
                    $("body").attr("style","display:block;");
                    return;
                }
                atuLoginToken();
            })
        });*/
    </script>
    <style type="text/css">
        .layui-table-tool-panel li .layui-form-checkbox[lay-skin=primary] {
            /* width: 100%; */
            padding-left: 28px;
        }

        .layui-table-tool-panel li {
            line-height: 30px;
            -webkit-transition: .5s all;
            transition: .5s all;
            padding-left: 10px;
            padding-right: 47px;
        }
    </style>
</head>

<body>
<div class="weadmin-nav">
			<span class="layui-breadcrumb" style="visibility: visible;">
			<a href="">任务管理</a><span lay-separator="">/</span>
			<a>
				<cite>调度日志</cite></a>
			</span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<!--表格-->
<div class="weadmin-body">
    <div class="layui-row">
        <table class="layui-hide" id="tableDataList" lay-filter="usertab"></table>
    </div>
</div>

<!--表格操作-->
<script type="text/html" id="op">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="selectLog">查看</a>
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-row">
        <div class="layui-col-md2">
            <div class="layui-form-item">
                <label class="layui-form-label">任务</label>
                <div class="layui-input-block">
                    <select autocomplete="off" id="jobaaId">
                        <option value="0" selected="">全部</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-md2">
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <select autocomplete="off" lay-filter="aihao" id="logStatus">
                        <option value="0" selected="">全部</option>
                        <option value="1">成功</option>
                        <option value="2">失败</option>
                        <option value="3">进行中</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md5">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">日期</label>
                        <div class="layui-inline" id="test6">
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off" id="startDate" class="layui-input"
                                       placeholder="开始日期">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" autocomplete="off" id="endDate" class="layui-input"
                                       placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md2">
            <button class="layui-btn layui-btn-sm" lay-event="getCheckData">搜索</button>
            <button class="layui-btn layui-btn-sm" lay-event="clearLog">清理</button>
        </div>
    </div>
</script>
<div class="layui-row" id="tableForm" style="display:none;">
    <div class="layui-col-md10">
        <form class="layui-form layui-from-pane" id="formId" style="margin-top:20px" lay-filter="tableForm">
            <div class="layui-form-item">
                <label class="layui-form-label">任务ID</label>
                <div class="layui-input-block">
                    <input type="text" disabled name="jobId" id="jobId" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">清理方式</label>
                <div class="layui-input-block">
                    <select name="type" required>
                        <option value="1">清理一个月之前日志数据</option>
                        <option value="2">清理三个月之前日志数据</option>
                        <option value="3">清理六个月之前日志数据</option>
                        <option value="4">清理一年之前日志数据</option>
                        <option value="5">清理一千条以前日志数据</option>
                        <option value="6">清理一万条以前日志数据</option>
                        <option value="7">清理三万条以前日志数据</option>
                        <option value="8">清理十万条以前日志数据</option>
                        <option value="9">清理所有日志数据</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" style="margin-top:40px">
                <div class="layui-input-block">
                    <button class="layui-btn  layui-btn-submit " lay-submit="" lay-filter="demo11">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/html" id="triggerStatusTpl">
    {{#  if(d.triggerStatus == 1 ){ }}
    <small class="label label-success">运行中</small>

    {{#  } else { }}
    <small class="label label-default">停止</small>

    {{#  } }}

</script>
<script type="text/html" id="triggerCodeTpl">
    {{#  if(d.triggerCode == 200 ){ }}
    <font style="color: #00FF00;">成功</font>

    {{#  } else { }}
    <font style="color: #ff1717">失败</font>
    {{#  } }}

</script>
<script type="text/html" id="handleCodeTpl">
    {{#  if(d.handleCode == 200 ){ }}
    <font style="color: #00FF00">成功</font>

    {{#  } else { }}
    <font style="color: #ff1717">失败</font>
    {{#  } }}

</script>
<script>
    layui.use(['util', 'laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function () {
        var util = layui.util;
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
            , layer = layui.layer //弹层
            , table = layui.table //表格
            , carousel = layui.carousel //轮播
            , upload = layui.upload //上传
            , element = layui.element //元素操作
            , form = layui.form;
        var logintoken = null;
        getSharreTieba_LoginToken();
        table.render({
            elem: '#tableDataList'
            , even: true //开启隔行背景
            , cellMinWidth: 80
            , toolbar: '#toolbarDemo'
            , url: global_visit_url_prefix + '/joblog/pageList'
            , cols: [[
                , {field: 'id', title: 'ID', hide: true}
                , {field: 'jobId', title: '任务ID', width: 180}
                , {field: 'triggerTime', title: '调度时间'}
                , {field: 'triggerCode', title: '调度结果',templet: '#triggerCodeTpl'}
                , {fixed: 'right', title: '调度备注', align: 'center', toolbar: '#op'}
                , {field: 'handleTime', title: '执行时间'}
                , {field: 'handleCode', title: '执行结果',templet: '#handleCodeTpl'}
                , {field: 'handleMsg', title: '执行备注'}
            ]],
            done: {}
            , page: true
        });

        //日期范围
        laydate.render({
            elem: '#test6'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            , range: ['#startDate', '#endDate']
        });
//监听行工具事件
        table.on('tool(usertab)', function (obj) { //注：tool 是工具条事件名，usertab 是 table 原始容器的属性 lay-filter="对应的值"
            debugger;
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent == 'selectLog') {
                layer.open({
                    title: '执行日志',
                    btn: ['确定'],
                    content: data.triggerMsg
                });
            }
        });

        var jobSelectData = function (val) {
            $.ajax({
                url: '/jobinfo/list',
                type: 'get',
                success: function (data1) {
                    var data = data1.data; //提出返回数据中的data
                    if (data !== null) {
                        $.each(data, function (index, item) { //循环加入 data的元素
                            if (val == item.id) {
                                $("#jobaaId").append("<option value='" + item.id + "' selected>" + item.jobDesc + "</option>");
                            } else {
                                $("#jobaaId").append("<option value='" + item.id + "'>" + item.jobDesc + "</option>");
                            }
                        });
                        form.render('select');
                        //$("#jobaaId").val(val);
                    }
                    ;
                }
            });
        };
        jobSelectData();

//监听表头
        table.on('toolbar(usertab)', function (obj) {
            //var checkStatus = table.checkStatus(obj.config.id);

            switch (obj.event) {
                case 'getCheckData':
                    var logStatus = $("#logStatus").val();
                    var startDate = $("#startDate").val();
                    var endDate = $("#endDate").val()
                    var jobId = $("#jobaaId").val();
                    table.reload('tableDataList', {
                        page: {
                            curr: 1
                        }
                        , where: {
                            logStatus: logStatus,
                            filterTime: startDate + "_" + endDate,
                            jobId: jobId
                        }
                    });
                    debugger;
                    jobSelectData(jobId);
                    $("#logStatus").val(logStatus);
                    $("#startDate").val(startDate);
                    $("#endDate").val(endDate);
                    break;
                case 'clearLog':
                    $("#jobId").val($("#jobaaId").val());
                    layer.open({
                        //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                        type: 1,
                        title: "日志清理",
                        area: ['520px', '430px'],
                        content: $("#tableForm")//引用的弹出层的页面层的方式加载修改界面表单
                    });
                    //动态向表传递赋值可以参看文章进行修改界面的更新前数据的显示，当然也是异步请求的要数据的修改数据的获取
                    clearLog();
                    break;
            }
            ;
        });

        //监听弹出框表单提交，massage是修改界面的表单数据'submit(demo11),是修改按钮的绑定
        function clearLog() {
            form.on('submit(demo11)', function (massage) {
                debugger;
                $.ajax({
                    url: '/joblog/clearLog',
                    type: 'get',
                    data: massage.field,
                    success: function (msg) {
                        table.reload("tableDataList");
                    }
                })
            })
        }
    });


</script>

</html>